/*
 * Copyright 2008 - 2009 Lars Heuer (heuer[at]semagia.com). All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.semagia.atomico.server.impl.restlet.resources;

import org.restlet.data.MediaType;
import org.restlet.data.Tag;
import org.restlet.representation.Variant;

/**
 * Atomico specific implementation of a {@link Variant}.
 * <p>
 * This class is meant to be used in conjunction with 
 * {@link AbstractAtomicoResource}. Instances of this class provide the 
 * necessary information to evaluate the HTTP conditional headers without 
 * creating a more expensive {@link org.restlet.resource.Representation}.
 * </p>
 * 
 * @see {@link AbstractAtomicoResource}
 * 
 * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
 * @version $Rev: 66 $ - $Date: 2010-09-06 15:29:07 +0000 (Mon, 06 Sep 2010) $
 */
final class AtomicoVariant extends Variant {

    /**
     * The modification time of this variant.
     */
    private final long _modified;

    /**
     * The HTTP conditional headers.
     */
    private final Tag _etag;

    /**
     * Creates a variant with the specified media type and modification time.
     * <p>
     * The eTag will be <tt>null</tt>.
     * </p>
     *
     * @param mediaType The media type, must not be <tt>null</tt>.
     * @param modified The modification time.
     */
    public AtomicoVariant(String mediaType, long modified) {
        this(mediaType, modified, null);
    }

    /**
     * Creates a variant with the specified media type and modification time.
     *
     * @param mediaType The media type, must not be <tt>null</tt>.
     * @param modified The modification time.
     * @param eTag A tag formatted as defined by the HTTP standard or 
     *              <tt>null</tt>.
     */
    public AtomicoVariant(String mediaType, long modified, String eTag) {
        super(MediaType.valueOf(mediaType));
        _modified = modified;
        _etag = eTag == null ? null : new Tag(eTag, true);
    }

    /**
     * Returns the ETag of this variant.
     *
     * @return The ETag or <tt>null</tt> if the ETag is not specified.
     */
    public Tag getETag() {
        return _etag;
    }

    /**
     * Returns the modification time of this variant.
     *
     * @return The modification time.
     */
    public long getModificationTime() {
        return _modified;
    }

}
